home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / cvt100.zip / VIDIO.C < prev    next >
Text File  |  1988-08-03  |  47KB  |  1,101 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <alloc.h>
  5.  
  6. #define NORMAL        0x7         /* Normal video attribute */
  7. #define BOLD          0x8         /* Bold video attribute */
  8. #define UNDERLINED    0xA         /* Underlined video attribute */
  9. #define REVERSE       0x70        /* Reverse video attribute */
  10. #define SCREEN        0x10        /* BIOS video interrupt number */
  11. #define RETRACE       0x3da       /* Video Retrace port address for CGA */
  12. #define ASCII         0           /* ASCII character set */
  13. #define UK            1           /* UK character set */
  14. #define SPECIAL       2           /* Special character set, graphics chars */
  15.  
  16. /****************************************************************************/
  17. /* Function prototypes                                                      */
  18.  
  19. void VidInit( void );             /* Initialize the video system */
  20. void SetVattr( unsigned char );   /* Set the video attribute */
  21. void AddVattr( unsigned char );   /* Add attribute to current video attribute*/
  22. void SubVattr( unsigned char );   /* Sub attribute from current vid attribute*/
  23. void BrkAtt( unsigned char );     /* Break attribute into extra and base */
  24. unsigned char AddAtt( void );     /* Add extra and base attributes to get */
  25.                                   /* a resulting displayable video attribute*/
  26. void ChrWrite( unsigned char );   /* Write character to the screen */
  27. void SetScroll(int , int );       /* Set the scrolling region */
  28. void ScrollDown( void );          /* Move down a row scrolling if necessary */
  29. void ScrollUp( void );            /* Move up a row scrolling if necessary */
  30. void IndexDown( void );           /* Scroll the screen down */
  31. void IndexUp( void );             /* Scroll the screen up */
  32. void SetCurs(int , int );         /* Set the cursor to absolute coordinates */
  33. void SetRelCurs(int , int );      /* Set the cursor to relative coordinates */
  34. void PosCurs( void );             /* Position the cursor to cursx,cursy */
  35. void ModeLine( void );            /* Display the Mode line */
  36. void ClearScreen( void );         /* Clear the terminal screen */
  37. void ClearEOS( void );            /* Clear from cursor to end of screen */
  38. void ClearBOS( void );            /* Clear from cursor to top of screen */
  39. void ClearEOL( void );            /* Clear from cursor to end of line */
  40. void ClearBOL( void );            /* Clear from cursor to start of line */
  41. void ClearBox( unsigned char,     /* Clear a box on the video screen */
  42.    unsigned char, unsigned char,
  43.    unsigned char, unsigned char);
  44. void MarCharSet( int );           /* Map a character set */
  45. void SetCharSet( int, unsigned char ); /* Set a character set */
  46. void SaveCursor( void );          /* Save the cursor description */
  47. void RestoreCursor( void );       /* Restore the cursor description */
  48. void SetCursorVisibility( int );  /* Set the cursor visibility mode */
  49. void SetBackGround( int );        /* Set background video attribute */
  50. void SetColor( void );            /* Set the screen colors */
  51. void InitTabs( void );            /* Initialize the tab settings */
  52. void DoTab( void );               /* Perform a tab */
  53. void SetTabStop( void );          /* Set a tab stop at cursor position */
  54. void ClearTabStop( void );        /* Clear a tab stop at the cursor position*/
  55. void ClearAllTabs( void );        /* Clear all the defined tab stops */
  56. void SetScreenWidth( int );       /* Set the logical width of the screen */
  57. void StartScreen( int, int );     /* Start a screen access */
  58. void EndScreen( void );           /* End a screen access */
  59. void WriteOneChar( unsigned char, /* Write one character to the screen */
  60.      int, int );
  61. int  VTprintf( int, int, int,     /* Printf for Emulator to row and column */
  62.      char *, ... );                  /* in regular or reverse video */
  63. void SaveScreen( void );          /* Save contents of video memory */
  64. void RestoreScreen( void );       /* Restore contents of video memory */
  65.  
  66. static void interrupt10( unsigned,/* Issue a BIOS video interrupt */
  67.   unsigned , unsigned , unsigned );
  68.  
  69.  
  70. /****************************************************************************/
  71. /* Global Data                                                              */
  72.  
  73. unsigned char retracemode = 0;    /* Flag indicating No Video refresh wait */
  74. unsigned char forecolor;          /* Foreground color */
  75. unsigned char backcolor;          /* Background color */
  76.  
  77. unsigned char vidmode;            /* Screen video mode */
  78.  
  79. /****************************************************************************/
  80. /* External variables                                                       */
  81.  
  82. extern unsigned originmode;       /* Origin mode, relative or absolute */
  83. extern unsigned insertmode;       /* Insert mode, off or on */
  84. extern unsigned autowrap;         /* Automatic wrap mode, off or on */
  85. extern unsigned newline;          /* Newline mode, off or on,  GLOBAL data!*/
  86. extern unsigned cursorvisible;    /* Cursor visibility, on or hidden */
  87. extern unsigned reversebackground;/* Reverse background attribute, on or off*/
  88. extern unsigned screenwid;        /* Absolute screen width */
  89.  
  90. extern char modeline[];           /* Text of mode line */
  91.  
  92. /***************************************************************************/
  93. /* Local static data                                                       */
  94.  
  95. static unsigned char screentop;   /* Absolute top of screen */
  96. static unsigned char screenbot;   /* Absolute bottom of screen */
  97. static unsigned char scrolltop;   /* Top row of scrolling region */
  98. static unsigned char scrollbot;   /* Bottom row of scrolling region */
  99.  
  100. static int cursx;                 /* X cursor position */
  101. static int cursy;                 /* Y cursor position */
  102.  
  103. static unsigned scroff;           /* Screen memory offset */
  104. static unsigned scrseg;           /* Screen memory segment */
  105. static unsigned scrchars;         /* Number of chars written to video memory */
  106. static unsigned char tvmode;      /* Flag to indicate control program present*/
  107. char far *screen;                 /* Pointer to video screen */
  108. static unsigned savebp;           /* Static storage for BP through int 0x10 */
  109.  
  110. static unsigned char video_state; /* State of video, reversed or normal */
  111. static unsigned char scbattr;     /* Video attribute of empty video cell */
  112. static unsigned char curattr;     /* Video attribute of displayable chars */
  113. static unsigned char baseattr;    /* Base attribute for video attributes */
  114. static unsigned char extrattr;    /* Extra attribute for video attributes */
  115.  
  116. static unsigned char att_reverse;          /* Reverse attribute bits */
  117. static unsigned char att_normal;           /* Normal attribute bits */
  118. static unsigned char att_low_mask  = 0x6;  /* Low attribute mask */
  119. static unsigned char att_underline = 0x1;  /* Underlined attribute bit */
  120. static unsigned char att_intensity = 0x8;  /* Bold attribute bit */
  121. static unsigned char att_blink     = 0x80; /* Blinking attribute bit */
  122.  
  123.  
  124. static unsigned columns;          /* Columns on logical terminal screen */
  125. static unsigned lines;            /* Lines on logical terminal screen */
  126.  
  127. static char tabs[132];            /* active tab stops */
  128. static char deftabs[132];         /* default tab stops, 9,17,26 .... */
  129.  
  130. static int G0 = ASCII;            /* Character set G0 */
  131. static int G1 = ASCII;            /* Character set G1 */
  132. static int *GL = &G0;             /* Pointer to current mapped character set*/
  133.  
  134. static char special_chars[32] = { /* Special characters */
  135.    32,4,176,9,12,13,10,248,241,18,11,217,191,218,192,197,
  136.    196,196,196,196,196,195,180,193,194,179,243,242,227,216,156,7
  137.    } ;
  138.  
  139. static struct SaveCursorStruct {  /* Structure to save cursor description */
  140.    int cursx;                        /* X cursor position, column */
  141.    int cursy;                        /* Y cursor position, row */
  142.    int *GL;                          /* pointer to mapped character set */
  143.    int G0;                           /* character set G0 */
  144.    int G1;                           /* character set G1 */
  145.